package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Slf4j
//@Aspect
public class Aspect01 {
    @Pointcut("@annotation (com.itheima.aop.MyLog)")
    private void pt(){}//private只能在当前类使用

    @Before("pt()")
    public void before(JoinPoint joinPoint){
        log.info("dcscs");
    }
    @Around("pt()")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        //获取目标对象的类名
        String name = joinPoint.getTarget().getClass().getName();
        log.info("目标对象的类名：{}",name);
        //获取目标方法的方法名
        String name1 = joinPoint.getSignature().getName();
        log.info("目标方法的方法名：{}",name1);
        //获取目标方法执行传入的参数是什么
        Object[] args = joinPoint.getArgs();
        log.info("目标方法执行时传入的参数：{}",Arrays.toString(args));
        //放行目标方法的执行
        Object proceed = joinPoint.proceed();
        //获取目标方法运行的返回值
        log.info("返回值：{}",proceed);
        return null;
    }
}
